
public class Game1_yjs {
	int x,y;
	int[][] res,res_bak,solute;
	public void init(int n,int m) {
		x=n;y=m;
		res = new int[n+2][m+2];
		res_bak = new int[n+2][m+2];
		solute = new int[n+2][m+2];
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				res[i][j] = 1;
				solute[i][j] = 0;
			}
		}
		for(int i=0;i<n+2;i++){
			res[i][0] = -1;
			solute[i][0] = -1;
			res[i][y+1] = -1;
			solute[i][y+1] = -1;
		}
		for(int i=0;i<m+2;i++){
			res[0][i] = -1;
			solute[0][i] = -1;
			res[x+1][i] = -1;
			solute[x+1][i] = -1;
		}
		copy(res, res_bak, x+2);
	}
	
	public void copy(int[][] r,int[][] s,int length){
		for(int i=0;i<length;i++){
			System.arraycopy(r[i], 0, s[i], 0, r[i].length);
		}
	}
	
	public void restart() {
		copy(res_bak, res, x+2);
		for(int i=1;i<=x;i++){
			for(int j=1;j<=y;j++){
				solute[i][j] = 0;
			}
		}
	}
	
	
	public void setValue(int i,int j) {
		res_bak[i][j] = 0;
	}
	public void setDisable(int i,int j) {
		res_bak[i][j] = -1;
	}
	
	public void change(int i,int j){
		if(res[i][j] == -1)
			return;
		else if(res[i][j] == 0)
			res[i][j]=1;
		else
			res[i][j]=0;
	}
	
	public void click(int i,int j){
		if(res[i][j] != -1){
			change(i, j);
			change(i-1, j);
			change(i+1, j);
			change(i, j-1);
			change(i, j+1);
			solute[i][j] = 1;
		}
	}
	
	public boolean isScc() {
		int cnt = 0;
		for(int i=1;i<=x;i++){
			for(int j=1;j<=y;j++){
				if(res[i][j] != -1)
					cnt+=res[i][j];
			}
		}
		if(cnt==0)
			return true;
		else
			return false;
	}
	
	
	public void printSolute() {
		for(int i=1;i<=x;i++){
			for(int j=1;j<=y;j++){
				System.out.print(solute[i][j]+"  ");
			}
			System.out.println();
		}
	}
	
	public boolean solute() {
		for(int i=0;i<Math.pow(2, y);i++){
			restart();
			String bString = Integer.toBinaryString(i); 
			char[] bChars = bString.toCharArray();
			for(int k=0;k<bChars.length;k++){
				if(bChars[k]=='1'){
					click(1, k+1);
					if(isScc())
						return true;
				}
			}
			for(int j=2;j<=x;j++){
				for(int k=1;k<=y;k++){
					if(res[j-1][k] == 1){
						click(j, k);
						if(isScc())
							return true;
					}
				}
			}
		}
		return false;
	}
	
	public static void main(String[] args) {
		Game1_yjs game = new Game1_yjs();
		game.init(2, 3);
		game.setDisable(1, 2);game.setDisable(2, 2);
		if(game.solute()){
			game.printSolute();
		}

	}
	
}
